﻿<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		
	</head>
	<body>
		<div id="app">
			<!--直接给出指令的参数-->
			<p v-pin:top = "100">
				Vue.js无难事
			</p>
			<!--使用动态参数-->
			<p v-pin:[direction]="100">
				Vue.js无难事
			</p>
		</div>
	
		<script src="vue.js"></script>
		<script>
			Vue.directive('pin', {
			  bind: function (el, binding, vnode) {
			  	el.style.position = 'fixed';
			  	let s = binding.arg || 'left';
	    		el.style[s] = binding.value + 'px'
			  }
			})
			new Vue({
			  el: '#app',
			  data: {
			  	direction: 'left'
			  }
			})
		</script>
	</body>
</html>